import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'

export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src'),
    },
  },
  server: {
    port: 3000,
    host: '0.0.0.0',
    cors: true
  },
  preview: {
    port: 80,
    host: '0.0.0.0',
    strictPort: true,
    allowedHosts: [
      'localhost',
      '.changdu.vip',
      '.changdu.ltd'  // 允许所有 changdu.ltd 的子域名
    ]
  },
  build: {
    chunkSizeWarningLimit: 1200,
    rollupOptions: {
      output: {
        manualChunks(id) {
          if (id.includes('node_modules')) {
            if (id.includes('element-plus')) {
              return 'element-plus'
            }
            if (id.includes('vue')) {
              return 'vue'
            }
            if (id.includes('echarts')) {
              return 'echarts'
            }
            // 其他大库可继续拆分
            return 'vendor'
          }
        }
      }
    }
  }
}) 